package client

import (
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/registry"
	"github.com/micro/go-plugins/registry/consul/v2"
	"gomicrodemo/proto/rand"
	"gomicrodemo/proto/user"
)

var (
	randClient rand.RandService
	userClient user.UserService
)

func GetRandClient() rand.RandService {

	if randClient == nil {
		consulRegistry := consul.NewRegistry(
			registry.Addrs("127.0.0.1:8500"),
		)

		service := micro.NewService(
			micro.Registry(consulRegistry),
		)
		randClient = rand.NewRandService("go.micro.homin.rand", service.Client())
	}

	return randClient
}

func GetUserClient() user.UserService {

	if randClient == nil {
		consulRegistry := consul.NewRegistry(
			registry.Addrs("127.0.0.1:8500"),
		)

		service := micro.NewService(
			micro.Registry(consulRegistry),
		)
		userClient = user.NewUserService("go.micro.homin.user", service.Client())
	}

	return userClient
}


